﻿using ET_DbCommon.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET_DbCommon.DAL
{
    public static class Paper_TestQuestion_Task_StepDAL
    {
        /// <summary>
        /// 查找考试试卷任务所属步骤
        /// </summary>
        /// <param name="Exam_TestQuestionId"></param>
        /// <returns></returns>
        public static List<Paper_TestQuestion_Task_StepModel> GetMyPaper_TestQuestion_Task_StepModel(int MyPaper_TestQuestion_TaskId)
        {
            List<Paper_TestQuestion_Task_StepModel> paper_TestQuestion_Task_StepModels = new List<Paper_TestQuestion_Task_StepModel>();
            string where = "where TaskId={0}";
            where = string.Format(where, MyPaper_TestQuestion_TaskId);
            using (var conn = MySqlHelper.GetConnection())
            {
                paper_TestQuestion_Task_StepModels = MySQLExt.GetByWhere<Paper_TestQuestion_Task_StepModel>(conn, where).ToList();
                if (paper_TestQuestion_Task_StepModels == null)
                    return null;
                return paper_TestQuestion_Task_StepModels;
            }
        }

        /// <summary>
        /// 查找考试试卷任务所属步骤
        /// </summary>
        /// <param name="Exam_TestQuestionId"></param>
        /// <returns></returns>
        public static List<Paper_TestQuestion_Task_StepModel> GetMyPaper_TestQuestion_Task_StepModelByOperationID(int operationID)
        {
            List<Paper_TestQuestion_Task_StepModel> paper_TestQuestion_Task_StepModels = new List<Paper_TestQuestion_Task_StepModel>();
            string where = "where OperateId={0}";
            where = string.Format(where, operationID);
            using (var conn = MySqlHelper.GetConnection())
            {
                paper_TestQuestion_Task_StepModels = MySQLExt.GetByWhere<Paper_TestQuestion_Task_StepModel>(conn, where).ToList();
                if (paper_TestQuestion_Task_StepModels == null)
                    return null;
                return paper_TestQuestion_Task_StepModels;
            }
        }

        public static int DeleteByID(int MyPaper_TestQuestion_TaskId)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                return MySQLExt.DeleteById<Paper_TestQuestion_Task_StepModel>(conn, MyPaper_TestQuestion_TaskId);
            }
        }

        public static void Insert(List<Paper_TestQuestion_Task_StepModel> stopModels)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                foreach (var model in stopModels)
                {
                    MySQLExt.InsertOrUpdate(conn, model);
                }
            }
        }

        public static int Insert(Paper_TestQuestion_Task_StepModel stepModel)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                return MySQLExt.InsertIdentityIndex(conn, stepModel);
            }
        }

        public static void Update(List<Paper_TestQuestion_Task_StepModel> steps)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                MySQLExt.UpdateByIdBatch(conn, steps);
            }
        }

        public static void Update(Paper_TestQuestion_Task_StepModel step)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                MySQLExt.UpdateById(conn, step);

            }
        }
    }
}
